/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package x10.interfaces.cm15a.receive;

import x10.utilities.ChunkOfBytes;
import x10.enums.InterfaceMessage;
import x10.enums.Interfaces;
import x10.event.X10Event;
import x10.event.X10InterfaceAcknowledge;

/**
 *
 * @author Denny
 */
public class IFResponseFactory extends X10DeviceReceiver {
    X10DeviceReceiver receiver;

    public IFResponseFactory(LastAddressedTracker lat, Interfaces interfaceType){
        super(lat, interfaceType);
    }

    public X10Event process(ChunkOfBytes bytes){
        X10Event device = null;
        if(bytes.getBytes()[0] == (byte)0x55){
            device = new X10InterfaceAcknowledge(bytes, interfaceType, Interfaces.CM15A.toString());
        } else if(bytes.getInterfaceMessage() == InterfaceMessage.STATUS_REQUEST_0X8B){
            receiver = new IFResponseStatus(lat, interfaceType);
            device = receiver.process(bytes);
        } else {
            System.out.println("Unknown Interface Response to: " + bytes.getInterfaceMessage());
            System.out.println(bytes.toString());
        }

        return device;
    }
}
